<%--
  Created by IntelliJ IDEA.
  User: YYY-Work
  Date: 2017/8/3
  Time: 16:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path;
%>
<!DOCTYPE>
<html>
<head>
    <title>确认健康档案</title>
    <meta charset="UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>

    <script type="text/javascript" src="<%=basePath%>/js/jquery-2.1.1.min.js"></script>

    <style type="text/css">
        .table th, .table td {
            text-align: center;
            vertical-align: middle !important;
        }
    </style>
</head>
<body class="skin-blue">
<s:action name="getHeader" namespace="/privilege" executeResult="true"/>
<div class="wrapper row-offcanvas row-offcanvas-left">

    <!-- Left side column. contains the logo and sidebar -->

    <!-- getMenus -->
    <s:action name="getMenus" namespace="/privilege" executeResult="true"/>

    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">

        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                <small>确认健康档案</small>
            </h1>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">

                        <div class="box box-danger">

                            <div class="box-body">
                                <input type="text" class="form-control" id="recid" value="${goodsDataUser.recid}"
                                       style="display: none"/>
                                <form action="javascript:void();" class="form-horizontal">

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">产品名称</label>
                                        <div class="col-sm-2">
                                            <input type="text" class="form-control" value="${goodsDataUser.itemName}"
                                                   disabled/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">用户姓名</label>
                                        <div class="col-sm-2">
                                            <input type="text" class="form-control" value="${goodsDataUser.ownerName}"
                                                   disabled/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">生效日期</label>
                                        <div class="col-sm-2">
                                            <input type="text" class="form-control" disabled
                                                   value='<fmt:formatDate value="${goodsDataUser.activateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>'/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">失效日期</label>
                                        <div class="col-sm-2">
                                            <input type="text" class="form-control" disabled
                                                   value='<fmt:formatDate value="${goodsDataUser.failureDate}" pattern="yyyy-MM-dd HH:mm:ss"/>'/>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label">就诊人姓名</label>
                                        <div class="col-sm-2">
                                            <c:if test="${not empty goodsDataUser.patientList}">
                                                <input type="text" class="form-control" disabled
                                                       value="${goodsDataUser.patientList.patientName}"/>
                                            </c:if>
                                            <c:if test="${empty goodsDataUser.patientList}">未知${goodsDataUser.patientList.patientName}"/>
                                            </c:if>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-1 control-label"></label>
                                        <div class="col-sm-2">
                                            <button type="button" class="btn btn-primary" onclick="sendToStuff()">确认通知医生接收</button>
                                        </div>
                                    </div>

                                </form>
                            </div><!-- /.box-body -->
                        </div><!-- /.box -->
                        <!-- 文章列表 -->

                        <div class="form-group">
                            <lable style="float: left;margin-left: 30px;font-weight: bold;font-size: 16px">问答列表</lable>
                            <button type="button" class="btn btn-primary btn-sm" style="margin-left: 15px" onclick="showAddUserRemark()">新增</button>
                        </div>
                        <form method="post" target="_self" action="" name="listForm">
                            <div class="box-body table-responsive" id="listDiv">

                                <s:property value="res" escape="false"/>
                            </div><!-- /.box-body -->
                        </form>

                    </div><!-- /.box -->


                </div>
            </div>

        </section><!-- /.content -->

    </aside>
</div>
</body>

<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="messageModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    新增问答
                </h4>
            </div>
            <div class="modal-body">
                <form id="add-form">

                    <input name="userDataId" value="${goodsDataUser.recid}" style="display: none"/>
                    <div class="form-group">
                        <label >问题</label>
                        <textarea type="text" class="form-control" id="question" name="question" style="width: 100%" rows="3"></textarea>
                    </div>

                    <div class="form-group">
                        <label >答案</label>
                        <textarea type="text" class="form-control" id="answer" name="answer" style="width: 100%" rows="6"></textarea>
                    </div>

                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" onclick="addUserRemark()" data-dismiss="modal">确定
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">取消
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="deleteAlertModal" tabindex="-1" role="dialog" aria-labelledby="messageModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    操作提示
                </h4>
            </div>
            <div class="modal-body">
                <label id="d_rec_id" style="display: none"></label>
                删除该条问答记录？
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" onclick="deleteUserRemark()" data-dismiss="modal">确定
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">取消
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="messageModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    编辑问答
                </h4>
            </div>
            <div class="modal-body" id="update-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" onclick="updateUserRemark()" data-dismiss="modal">确定
                </button>
                <button type="button" class="btn btn-primary" data-dismiss="modal">取消
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script type="text/javascript" src="<%=basePath%>/js/admin/utils.js"></script>
<script type="text/javascript" src="<%=basePath%>/js/base/listtable.js"></script>
<link href="<%=basePath%>/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>
<link href="<%=basePath%>/themes/explorer/theme.css" media="all" rel="stylesheet" type="text/css"/>
<script src="<%=basePath%>/js/sortable.js" type="text/javascript"></script>
<script src="<%=basePath%>/js/fileinput.js" type="text/javascript"></script>
<script src="<%=basePath%>/js/locales/zh.js" type="text/javascript"></script>
<script src="<%=basePath%>/themes/explorer/theme.js" type="text/javascript"></script>

<script type="text/javascript">


    function searchGoodsDataUser() {

        var recid = Utils.trim($("#recid").val());

        if (!Utils.isEmpty(recid)) {
            listTable.filter['userDataId'] = recid;
            listTable.filter['currentPage'] = 1;
            listTable.action = "<%=basePath%>/healthrecord/ajaxQueryGoodsDataUserRemarks.action";

            listTable.loadList();
        }
    }

    function showDeleteUserRemark(recid) {
        $("#d_rec_id").html(recid);
        $('#deleteAlertModal').modal('show');
    }
    
    function showAddUserRemark() {
        $("#question").val("");
        $("#answer").val("");
        $('#addModal').modal('show');
    }

    function deleteUserRemark() {

        var recid = $("#d_rec_id").html();

        $.ajax({
            type: "POST",
            url: "<%=basePath%>/healthrecord/ajaxDeleteGoodsDataUserRemark.action",
            data: "recid="+recid,
            async: true,
            error: function (request) {
                alert("网络异常");
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.errorCode >= 0) {
                    listTable.loadList();
                } else {
                    alert(data.errorMsg);
                }
            }
        });
        $('#deleteAlertModal').modal('hide');
    }
    
    function queryRemarkForUpdate(recid) {
        $.ajax({
            type: "POST",
            url: "<%=basePath%>/healthrecord/ajaxQueryGoodsDataUserRemarkForUpdate.action",
            data: "recid="+recid,
            async: true,
            error: function (request) {
                alert("网络异常");
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.errorCode >= 0) {
                    $("#update-body").empty();
                    $("#update-body").append(data.content);
                    $('#updateModal').modal('show');
                } else {
                    alert(data.errorMsg);
                }
            }
        });
    }
    
    function updateUserRemark() {
        var formData =new FormData($('#update-form')[0]);//
        $.ajax({
            type: "POST",
            url:"<%=basePath%>/healthrecord/ajaxUpdateGoodsDataUserRemark.action",
            data:formData,
            async: false,
            contentType: false,
            processData: false,
            error: function(request) {
                alert("网络异常");
            },
            success: function(data) {
                data=JSON.parse(data);
                if (data.errorCode>=0)
                {
                    alert("编辑成功");
                    listTable.loadList();
                }else
                {
                    alert(data.errorMsg);
                }
            }
        });
        $('#updateModal').modal('hide');
    }

    function addUserRemark() {
        var formData =new FormData($('#add-form')[0]);//
        $.ajax({
            type: "POST",
            url:"<%=basePath%>/healthrecord/ajaxAddGoodsDataUserRemark.action",
            data:formData,
            async: false,
            contentType: false,
            processData: false,
            error: function(request) {
                alert("网络异常");
            },
            success: function(data) {
                data=JSON.parse(data);
                if (data.errorCode>=0)
                {
                    alert("新增成功");
                    listTable.loadList();
                }else
                {
                    alert(data.errorMsg);
                }
            }
        });
        $('#addModal').modal('hide');
    }

    $(document).ready(new function () {
        searchGoodsDataUser();
    });

    function sendToStuff() {
        var recid = $("#recid").val();
        $.ajax({
            type: "POST",
            url: "<%=basePath%>/healthrecord/ajaxSendGoodsDataUserToStuff.action",
            data: "recid="+recid,
            async: true,
            error: function (request) {
                alert("网络异常");
            },
            success: function (data) {
                data = JSON.parse(data);
                if (data.errorCode >= 0) {
                    alert("确认成功");
                } else {
                    alert(data.errorMsg);
                }
            }
        });
    }

</script>


</html>
